#!/usr/bin/python3

import os

class API_Keys:

    def __init__(self):
        self.count = 0;
        self.current = 0;
        self.keys  = []
        pass

    # 文件格式
    # sk-aaaa\n
    # sk-bbbb\n
    # sk-cccc\n
    # sk-dddd\n
    def load_pool(self, fpath="/home/cloud/apikeys"):
        fp = open(fpath)
        self.keys  = []
        # keys = []
        for line in fp.readlines():
            if line == "\n" or line == "\r\n":
                continue;
            # 分离出每行末尾的\n
            self.keys.append(line.split('\n')[0])
        fp.close()
        self.count = len(self.keys)

    def get_item(self):
        item = self.keys[self.current]
        self.current = (self.current + 1) % self.count
        return item
